package cn.kogee.controller;

import cn.kogee.domian.Student;
import cn.kogee.domian.User;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCollapser;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@DefaultProperties(defaultFallback = "fallbackGetById")
public class Ordercontroller {
    @Autowired
    private RestTemplate restTemplate;
    @GetMapping("/getById/{id}")
    public Object GetById(@PathVariable("id") Long id){
      /*直接调用  String Url="http://localhost:1020/getById/"+id;*/
        String Url="http://user-server/getById/"+id;
        return restTemplate.getForObject(Url,User.class);
    }
/*  独立托底方法  public User fallbackGetById(@PathVariable("id") Long id){
        *//*直接调用  String Url="http://localhost:1020/getById/"+id;*//*
        return new User(-1L,"触发熔断机制","服务被熔断，请稍后重试！！");
    }*/
    @GetMapping("/{id}")
    public Object getst(@PathVariable("id") Long id){
        /*直接调用  String Url="http://localhost:1020/getById/"+id;*/
        String Url="http://user-server/"+id;
        return restTemplate.getForObject(Url, Student.class);
    }
    /**
     * 统一托底方法
     * @param
     * @return
     */
    public Object fallbackGetById(){//@PathVariable("id")Long id统一托底不需要改注解
        return new User(-1L,"统一托底方法触发熔断机制","服务被熔断，请稍后重试！！");
    }
}
